﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using wfDesigner.ViewModel;
using Microhard.WorkflowDataAccess;

namespace wfDesigner
{
    /// <summary>
    /// UpdateFlowTypeWindow.xaml 的交互逻辑
    /// </summary>
    public partial class UpdateFlowTypeWindow : Window
    {
        public UpdateFlowTypeWindow()
        {
            InitializeComponent();
        }

        private void UpdateBtn_Click(object sender, RoutedEventArgs e)
        {            
            FlowTypeViewModel vm = (FlowTypeViewModel)this.DataContext;
            Guid typeid = vm.TypeList[vm.SelIndex].TypeID;
            try
            {
                WorkflowDBDataContext entity = new WorkflowDBDataContext();
                var s = entity.t_WorkFlowTypes.Where(n => n.TypeId == typeid).SingleOrDefault();

                s.TypeName = this.TypeNameTxt.Text;
                s.TypeRemark = this.RemarkTxt.Text;

                entity.SubmitChanges();
            }
            catch
            {
                MessageBox.Show("修改失败！", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                this.Close();
            }
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
